<?php
	include(str_replace("\\", "/", dirname(__FILE__))."/conn.php"); 
	include(str_replace("\\", "/", dirname(__FILE__))."/TweetBot.php");  
    $password='qingyu';
	$username='cmd_14@126.com';   
	$bot = new TweetBot("cmd_14");    
	$html=$bot->login($username,$password);  
	$action = "";
	if(isset($_REQUEST['do'])){
		$action = "";
		//第二次再reply 
		$sql = "select * from en_article  order by replynum asc limit 1 ;";
		$en_article = query($sql);  
		$sql = "update en_article set ispost = 1 , replynum = replynum+1 where articleid = '".$en_article[0]['articleid']."'";
		mysql_query($sql); 
		$sql = "select * from twitter_reply where isreply = 0 order by gettime desc limit 1;";
		$reply = query($sql);
		$sql = "update twitter_reply set isreply = 1 where id = '".$reply[0]['id']."'";
		mysql_query($sql);  

		echo "\n";
		$reply_url = short_url("http://mall0592.duapp.com/index.php?_t=".date("Y/d/m/H/i/s",time())."&c=f"); 
		echo $msg = "@".$reply[0]['user']."  Daily News : ".html_decode($en_article[0]['title'])."  ".$reply_url;  
		$html = $bot->reply($reply[0]['pid'],$msg); 
		if(strpos($html, '{"error":"403"')){
			$response = json_decode(substr($html, strpos($html, '{"error":"403"')),true); 
			slog($username,$response['message']);
		}

	}else{

		$action = "?do=1";
		$sql = "select * from en_article  order by replynum asc limit 1 ;";
		$en_article = query($sql);  
		$sql = "update en_article set ispost = 1 , replynum = replynum+1 where articleid = '".$en_article[0]['articleid']."'";
		mysql_query($sql); 

		$reply_url = short_url("http://mall0592.duapp.com/index.php?_t=".date("Y/d/m/H/i/s",time())."&c=f"); 
		$msg = html_decode($en_article[0]['title'])."  ".$reply_url;

		$bot->create($msg); 

		//加1个好友
		$sql = "select * from twitter_reply where isfollow = 0 order by gettime desc limit 1;";
		$reply = query($sql);
		$sql = "update twitter_reply set isfollow = 1 where id = '".$reply[0]['id']."'";
		mysql_query($sql);  
		$bot->follow($reply[0]['userid']); 


	}
	//发表一篇带图片 
	
?>
<script type='text/javascript'>
	setTimeout("location.href='postreply_cmd_14.php<?php echo $action;?>'",1000*60*<?php echo rand(10,15);?>);
</script>